import typing
from typing import List
import numpy as np
# 题目：输入一个矩阵，按照从外向里以顺时针的顺序一次打印出每一个数字
# 例如对于矩阵 ：
# [[ 1,  2,  3,  4],
#  [ 5,  6,  7,  8],
#  [ 9, 10, 11, 12],
#  [13, 14, 15, 16]]

# 应该输出 1，2，3，4，8，12，16，15，14，13，9，5,6，7，11，10

def print_matrix_clock_wise(numbers:List[List[int]])->None:
    if not numbers:
        return
    rows= len(numbers)
    if rows<1:
        return None
    columns = len(numbers[0])
    if columns<1:
        return

    start = 0
    while (columns > start*2) and (rows>start*2):
        _print_matrix_circle(numbers, rows, columns,start)
        start += 1


def _print_matrix_circle(numbers, rows,columns,start):

    endx = columns-start
    endy = rows-start

    # 从左至右打印第一行
    for i in range(start, endx):
        print(numbers[start][i], end=' ')

    # 从上至下打印一列
    if start<endy-1:
        for i in range(start+1, endy):
            print(numbers[i][endx-1],end=' ')

    # 从右至左打印一行
    if start<endx and start<endy-1:
        for i in range(endx-2,start-1,-1):
            print(numbers[endy-1][i],end=' ')

    if start<endx and start<endy-2:
        for i in range(endy-2, start, -1):
            print(numbers[i][start],end=' ')


if __name__ == '__main__':
    numbers = np.arange(1,26).reshape(5,5)
    print(numbers)
    numbers = numbers.tolist()
    print_matrix_clock_wise(numbers)


